<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="execte">点击我执行命令</button>
<button id="undo">点击我执行命令</button>
<script>
    var Tv = {
        open:function () {
            console.log("打开电视机");
        },
        close:function () {
            console.log("关上电视机")
        }
    }
    var OpenTvCommand = function (receiver) {
        this.receiver=receiver;
    }
    OpenTvCommand.prototype.ececute = function () {
        this.receiver.open();
    }
    OpenTvCommand.prototype.unbo = function () {
        this.receiver.close()
    }
    var setCommand = function (command) {
        document.getElementById("execte").onclick=function () {
            command.ececute();
        }
        document.getElementById("undo").onclick= function () {
            command.unbo()
        }
    }
    setCommand(new OpenTvCommand(Tv))
</script>
</body>
</html>